var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){

	var url = tl_config.his_url;
	var start =url.indexOf('?')+1;
	var params = url.substring(start);
	var parr = [];
	var paramMap = {
	};
	parr = params.split('&');
	for(var i in parr){
		var key=parr[i].substring(parr[i].indexOf('='),0);
		paramMap[key]=parr[i].substring(parr[i].indexOf('=')+1);
	}
	var id = paramMap['id'];

	$("#staffInfoBack").click(function(){
		var url='staffList.do?ran='+Math.random();
		tl_config.loadToWorkArea(url);
	});


	$.ajax({
		type : 'GET',
		contentType : 'application/json',
//		async : false,
		data : {
			userid : id,
			token:token
		},
		url : server_url+'rest/getStaff.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if (data.retCode == "0000") {
				pasteData(data.data);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});

	//数据权限
	$.ajax({
		type : 'GET',
//		async : false,
		data : {
			staffId : id,
			token:token
		},
		url : server_url+'rest/checkPrecinct.do?ran='+Math.random(),
		dataType : 'json',
		success : function(data) {
			if (data.retCode == "0000") {
				if(data.data!=null){
					var settings={
						keyName:"areaId",
						parentKeyName:"parentId",
						childKeyName:"nodes"
					};
					var area=transformTozTreeFormat(settings,data.data);
					$.fn.tree.init({nodes:area});

					$(".z_zone input").css("display","none");
					$(".z_zone p").css("margin-left","14px");
//					$(".z_zone div").removeClass("z_gone");
//					$(".z_zone span").css("background","none");
//					$(".z_zone p").css("margin-left","14px");
				}
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});

	function pasteData(data){
//		console.log(data.staffNo);
		$("#staffNo").text(data.staffNo);
		$("#loginName").text(data.loginName);
		$("#staffName").text(data.staffName);

		isEmpty(data.sex)?$("#sex").text(""):$("#sex").text(data.sex);

		if(isEmpty(data.birthday)){
			$("#birthday").text("");
		}else{
			var birthday=data.birthday;
			$("#birthday").text(birthday.substring(0,10));
		}

//		console.log(data.areaText);
		isEmpty(data.areaText)?$("#area").text(""):$("#area").text(data.areaText);

//		console.log(data.employTime);
		if(isEmpty(data.employTime)){
			$("#employTime").text("");
		}else{
			var employTime=data.employTime;
//			console.log(employTime);
			$("#employTime").text(employTime.substring(0,10));
		}

		isEmpty(data.employStatus)?$("#employStatus").text(""):$("#employStatus").text(data.employStatus);

		isEmpty(data.mobile)?$("#mobile").text(""):$("#mobile").text(data.mobile);

		isEmpty(data.email)?$("#email").text(""):$("#email").text(data.email);

		isEmpty(data.weixin)?$("#weixin").text(""):$("#weixin").text(data.weixin);

		isEmpty(data.qq)?$("#qq").text(""):$("#qq").text(data.qq);

		isEmpty(data.telePhone)?$("#telePhone").text(""):$("#telePhone").text(data.telePhone);

		isEmpty(data.staffDesc)?$("#staffDesc").text(""):$("#staffDesc").text(data.staffDesc);

		var post2OrgVos=data.post2OrgVos;
		if(post2OrgVos!=null&&post2OrgVos.length!=0){
			for(var i=0;i<post2OrgVos.length;i++){
//				console.log(post2OrgVos[i].orgName);
//				console.log(post2OrgVos[i].postName);
				var postorg="<tr><td>"+post2OrgVos[i].orgName+"</td><td>"+post2OrgVos[i].postName+"</td></tr>";
				$("#post2OrgVo").append(postorg);
			}
		}
	}

});

function isEmpty(data){
	if(data==null||data==undefined||data.length==0){
		return true;
	}else{
		return false;
	}
}

